//点击返回顶部
let scrolltop = document.documentElement.scrollTop
$("#foot ul .li3").click(function () {
    $("html,body").animate({ scrollTop: 0 }, 500)
})
//点击返回图标返回上一页
$("#header .fh").click(function(){
    window.location.href="gnzk_list.html"
})
//处理url
let reg = /([^&=]+)=?([^&]*)/g
let str = window.location.href
var productId = parseInt(reg.exec(str)[2])
console.log(productId);
//请求数据渲染页面
fetch(`http://chst.vip:1234/api/getdiscountproduct?productid=${productId}`)
.then(body=>body.json())
.then(res=>{
    let obj = res.result[0]
    let str =`
<div class="xqmod">
    <h4>${obj.productName}</h4>
    <p class="product">
        <span class="pt left">${obj.productFrom}|1${obj.productTime}</span>
        <span class="pt right">${obj.productTips}</span>
        <span class="pt new">${obj.productPrice}</span>
    </p>
    <div class="text">
        <p>${obj.productInfo}</p>
        ${obj.productImg}
    </div>
</div>
<ul class="yhmod">

</ul>
<div class="gmmod">
    <a href="#">前往购买</a>
    <img src="http://chst.vip:8081/for-stu/wfzh/images/mmbweixin2.png" alt="">
</div>
<div class="plmod">
${obj.productComment}
</div>
<div id="more">
    <p>更多优惠信息&gt;&gt;</p>
</div>
    `
    $("#main").html(str)
})